﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Cloud.Model;
using Cloud.BLL;
using System.Configuration;
public partial class Three_Managerment_P0501_List_All : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            if (!IsPostBack)
            {
                #region 下拉数据绑定
                this.gs_drop.DataSource = AscriptionManager.FindAll();
                this.gs_drop.DataTextField = "name";
                this.gs_drop.DataValueField = "id";
                this.gs_drop.DataBind();
                this.gs_drop.Items.Insert(0, new ListItem("全部", "0"));

                this.sqly_drop.DataSource = SourcesManager.FindAll();
                this.sqly_drop.DataTextField = "name";
                this.sqly_drop.DataValueField = "id";
                this.sqly_drop.DataBind();
                this.sqly_drop.Items.Insert(0, new ListItem("全部", "0"));
                #endregion
                bind("1");
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        try
        {
            if (Session["users"] == null)
            {
                Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            }
            bind(AspNetPager1.CurrentPageIndex.ToString());
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    public void bind(String pag)
    {
        try
        {
            string strsjzt = "";
            string strsjid = "";
            string strgs = "";
            string strsqly = "";
            string strbegtime = "";
            string strtimeend = "";
            string strtitle = "";
            string strtel = "";
            string strgnum = "";
            string strgtext = "";

            #region MyRegion


            if (title.Value.Equals(""))
            {

            }
            else
            {
                strtitle = " and title like '%'+'" + title.Value + "'+'%' ";
            }


            if (tel.Value.Equals(""))
            {

            }
            else
            {
                strtel = " and appeal_tel = '" + tel.Value + "' ";
            }
            if (gnum.Value.Equals(""))
            {

            }
            else
            {
                strgnum = " and jobnum =" + gnum.Value + " ";
            }

            #endregion
            #region 诉求来源 1
            if (sqly_drop.SelectedItem.Value.Equals("0"))
            {

            }
            else
            {
                strsqly = " and source_id =" + sqly_drop.SelectedItem.Value + " ";
            }
            #endregion
            #region 归属 1
            if (gs_drop.SelectedItem.Value.Equals("0"))
            {

            }
            else
            {

                strgs = " and ascription_id =" + gs_drop.SelectedItem.Value + " ";
            }
            #endregion
            #region 事件id  1


            if (sjid_input.Value.Equals(""))
            {

            }
            else
            {
                strsjid = " and appealid  like '%'+'" + sjid_input.Value + "'+'%' ";
            }
            #endregion
            #region 事件状态下拉  1

            if (sjzt_drop.SelectedItem.Value.Equals("0"))
            {

            }
            else if (sjzt_drop.SelectedItem.Value.Equals("1"))
            {
                strsjzt = " and handle_type = 0 ";
            }
            else if (sjzt_drop.SelectedItem.Value.Equals("2"))
            {
                strsjzt = " and handle_type = 2 ";
            }
            else if (sjzt_drop.SelectedItem.Value.Equals("3"))
            {
                strsjzt = " and handle_type = 3 ";
            }
            else if (sjzt_drop.SelectedItem.Value.Equals("4"))
            {
                strsjzt = " and handle_type = 4 ";
            }

            #endregion
            #region 时间
            if (!this.timebeg.Value.Equals("") && !this.timeend.Value.Equals(""))
            {
                if (Convert.ToDateTime(this.timeend.Value) < Convert.ToDateTime(this.timebeg.Value))
                {
                    Response.Write("<script>alert('时间选择错误')</script>");
                }
            }
            if (!this.timebeg.Value.Equals(""))
            {
                strbegtime = " and regtime > '" + this.timebeg.Value + "' ";
            }

            if (!this.timeend.Value.Equals(""))
            {
                strtimeend = " and regtime < '" + this.timeend.Value + "' ";
            }
            #endregion

            String sql1gd = "select top 10 * from problem where id not in (select top (10 * (";
            String sql2page = pag;
            String sql3gd = "-1))   ";
            String sql4tj = strsjid + strsjzt + strgs + strsqly + strbegtime + strtimeend + strtitle + strtel + strgnum + strgtext +" and zrdwid='" + ((USER_INFO)Session["users"]).DEPARTMENT + "'"; 
            String sql5gd = " id from problem where 1=1" + sql4tj + " order by regtime desc) ";
            String sql6tj = strsjid + strsjzt + strgs + strsqly + strbegtime + strtimeend + strtitle + strtel + strgnum + strgtext+" and zrdwid='" + ((USER_INFO)Session["users"]).DEPARTMENT + "'";
            String sql7gd = "  order by regtime desc ";
            String sqls = sql1gd + sql2page + sql3gd + sql5gd + sql6tj + sql7gd;


            AspNetPager1.PageSize = 10;//设置分页大小 
            AspNetPager1.RecordCount = Convert.ToInt32(ProblemManager.Count_ALL(sql4tj));//设置总数据条数 

            repeater.DataSource = ProblemManager.Count_ALL_page(sqls); ;
            repeater.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
    protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rep1") as Repeater;//找到里层的repeater对象
                Problem rowv = (Problem)e.Item.DataItem;//找到分类Repeater关联的数据项 
                int typeid = Convert.ToInt32(rowv.Source_id); //获取填充子类的id 
                IList<Sources> sou = new List<Sources>();
                sou.Add(SourcesManager.FindById(typeid));
                rep.DataSource = sou;
                rep.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    //事件状态
    public string sjzt(int i)
    {
        try
        {
            String zts = "";
            if (i == 0)
            {
                zts = "待办理";
            }
            else if (i == 1)
            {
                zts = "办理中";
            }
            else if (i == 2)
            {
                zts = "已办理";
            }
            else if (i == 3)
            {
                zts = "已办结";
            }
            else if (i == 4)
            {
                zts = "直办";
            }
            return zts;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return "";
        }

    }
    protected void Unnamed_Click(object sender, EventArgs e)
    {
        this.bind("1");
    }
}